package com.budwk.app.sqfwV2.generator.centuryCitySecurity.excel.V2;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.models.Sqfw_formSummary_new;
import com.budwk.app.sqfwDoc.bo.SqfwExcelForSummaryBO;
import com.budwk.app.sqfwDoc.bo.SqfwExcelJudgeRes;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.BaseTemplateExcelGenerator;
import com.budwk.app.sqfwDoc.codeGenerator.excelGenerate.SqfwExcelCreateCommonBO;
import com.budwk.app.sqfwV2.component.DayingRoadPdfComponent;
import com.budwk.app.sqfwV2.component.centuryCity.CommCenturyCityDataHandleUtil;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckGasDTO;
import com.budwk.app.sqfwV2.dto.dto.centuryCity.SafeCheckTaskPdfDTO;
import com.budwk.app.sqfwV2.dto.image.CenturyCityExcelImageConfigBO;
import com.budwk.app.sqfwV2.enums.CenturyCitySafeCheckGasUseEnum;
import com.budwk.app.sqfwV2.enums.jinYang.JinYangExcelEnum;
import com.budwk.app.util.poiUtils.excelPictureConfigBO.ExcelFileCreateParamBO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 东方祥云低代码1.1
 * @since 2024-02-18
 * <p>
 * 世纪城安全巡查表 safe_check_task
 * 燃气使用统计清单.xlsx
 */
@Slf4j
public class GasUseStatisticsGeneratorV2 extends BaseTemplateExcelGenerator {

    @Override
    protected void customerPopularSheetBaseParam(Map<String, Object> excelParam, SqfwExcelCreateCommonBO excelCreateParam) {
        CommCenturyCityDataHandleUtil.buildUnitName(excelParam, excelCreateParam);
    }

    @Override
    protected void customerPopularSheetDataParam(List<Map<String, Object>> listMap, SqfwExcelCreateCommonBO excelCreateParam) {
    }

    @Override
    protected String getTemplateName() {
        return JinYangExcelEnum.GAS_USE_STATISTICS.getTemplatePath();
    }

    @Override
    public String getDownloadFileName() {
        String fileName = DayingRoadPdfComponent.getDictName(JinYangExcelEnum.GAS_USE_STATISTICS.getCode(), null);
        if (StringUtils.isBlank(fileName)) {
            fileName = JinYangExcelEnum.GAS_USE_STATISTICS.getFileName();
        } else {
            fileName = fileName.split("\\.")[0];
        }
        return fileName + "_" + DateUtil.format(new Date(), "yyyyMMddHHmmss");
    }

    @Override
    protected void completeExcelFileCreateParam(ExcelFileCreateParamBO excelFileCreateParam) {

    }

    @Override
    protected void customerPopularRowDataMap(Map<String, Object> rowDataMap, SqfwExcelForSummaryBO forSummaryBO) {
        Sqfw_formSummary_new sqfwFormSummaryNew = forSummaryBO.getSqfwFormSummaryNew();
        SafeCheckTaskPdfDTO safeCheckTaskPdfDTO = JSONObject.parseObject(sqfwFormSummaryNew.getParamData(), SafeCheckTaskPdfDTO.class);
        SafeCheckGasDTO safeCheckGasDTO = safeCheckTaskPdfDTO.getSafeCheckGasDTO();
        String fireAndElectricityUsageStr = null;
        for (String code : safeCheckGasDTO.getFireAndElectricityUsage().split(",")) {
            //燃气使用情况 先判断是否在枚举里面且是要写入此表的数据，金阳后面新加的集中燃料不计入此excel
            CenturyCitySafeCheckGasUseEnum fireAndElectricityUsage = CenturyCitySafeCheckGasUseEnum.getGasUseStatisticsEnum(code);
            if (ObjectUtils.isNotEmpty(fireAndElectricityUsage)) {
                String value = CenturyCitySafeCheckGasUseEnum.New_type_of_fuel.getCode().equals(code) ? String.format("%s(%s)", fireAndElectricityUsage.getValue(), safeCheckGasDTO.getNewFuel()) : fireAndElectricityUsage.getValue();
                if (StringUtils.isBlank(fireAndElectricityUsageStr)) {
                    fireAndElectricityUsageStr = value;
                } else {
                    fireAndElectricityUsageStr = fireAndElectricityUsageStr + ";" + value;
                }
            }
        }
        rowDataMap.put("fireAndElectricityUsage",fireAndElectricityUsageStr);
        rowDataMap.put("otherHiddenDangers", safeCheckGasDTO.getOtherHiddenDangers());
        rowDataMap.put("crossRegionalDelivery", safeCheckGasDTO.getCrossRegionalDelivery());
        rowDataMap.put("fillDateStr", DateUtil.format(sqfwFormSummaryNew.getFillDate(), "yyyy年MM月dd日"));
        rowDataMap.put("remark", safeCheckGasDTO.getRemark());


        //CommCenturyCityDataHandleUtil.rowDataBuild(rowDataMap, forSummaryBO);
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeErgodic(SqfwExcelCreateCommonBO excelCreateParam, Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected SqfwExcelJudgeRes judgeDataIntoExcelBeforeCreate(Map<String, Object> excelParam) {
        return null;
    }

    @Override
    protected Class<?> getImageConfigBO() {
        return CenturyCityExcelImageConfigBO.class;
    }

    public boolean isGenerateExcel(List<Sqfw_formSummary_new> dataList) {
        return CommCenturyCityDataHandleUtil.checkData(dataList);
    }

}
